<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title th:text="${shop.name+'-订单管理'}"></title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .update {
            display: inline-block;
            margin-left: 15px;
            padding: 0 20px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #009789;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            cursor: pointer;
        }

        .update i {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
            width: 30px;
            height: 30px;
            background: url();
        }
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 250px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }
    </style>
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li><a th:href="@{/douyin/dashboard(shopId=${shopId})}">首页</a></li>
            <li class="layui-this"><a th:href="@{/douyin/order_list(shopId=${shopId})}">订单管理</a></li>
            <li><a class="order-item" th:href="@{/douyin/refund_list(shopId=${shopId})}">退货管理</a></li>
            <li><a target="_blank" th:href="@{/douyin/order_print_list(shopId=${shopId},print=0)}" style="color: #eb7350;">打单工具</a></li>
            <li><a href="/shop/shop_list_dy" style="color: #9F9F9F;font-size:small;">选择店铺</a></li>
            <li><a href="/fahuo/wait_confirm_order_list_dy" >待确认订单</a></li>

        </ul>
    </div>

    <!-- content starts -->
<!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
<!--            <div class="layui-inline">-->
<!--                <form method="post" enctype="multipart/form-data" id="execl_form">-->
<!--                    <input type="file" name="excel" id="excel" placeholder="" class="layui-input">-->
<!--                </form>-->
<!--            </div>-->

<!--            <div class="layui-inline">-->
<!--                <button type="button" id="excel_upload_btn" class="layui-btn">上传excel</button>-->
<!--                <span id="excel_upload_btn_" style="display: none;" class="update"><i></i>导入中</span>-->
<!--            </div>-->
            <form class="layui-form layui-form-pane1" method="get" action="/douyin/order_list">
                <input type="hidden" name="shopId" th:value="${shop.id}" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" th:value="${orderNum}" placeholder="订单编号" style="width: 200px;" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text"   class="layui-input" name="startTime" th:value="${startTime}" id="startTime" autocomplete="off"
                                  style="width: 160px;" placeholder="yyyy-MM-dd">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  class="layui-input" name="endTime" th:value="${endTime}" id="endTime" style="width: 160px;" autocomplete="off" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="logisticsCode" th:value="${logisticsCode}" placeholder="物流单号" style="width: 200px;" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">订单状态</option>
                                <option th:each="item:${T(com.b2c.entity.enums.third.EnumDouYinOrderStatus).values()}" th:value="${item.getThirdIndex()}" th:text="${item.getName()}">等待发货</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-normal">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <span id="upd_order" class="layui-btn layui-btn-normal" th:attr="shopId=${shop.getId()}">更新抖店订单数据</span>
                        <span id="upd_order_" style="display: none;" class="update"><i></i>更新中</span>
                    </div>

                    <div class="layui-inline">
                        <button type="button" lass="button" id="excel_btn" class="layui-btn layui-btn-primary">导出订单</button>
                    </div>

                    <div class="layui-inline">
                        <span id="confirm_order" class="layui-btn layui-btn-disabled">批量确认（抖单打单)</span>
                        <span id="confirm_order_" style="display: none;" class="update"><i></i>批量确认中</span>
                    </div>
                    <div class="layui-inline">
                        <a  target="_blank" th:href="@{/douyin/order_print_list(shopId=${shopId},print=0)}"  class="layui-btn layui-btn-normal">打单工具（电子面单）</a>
                        <a type="button" th:href="@{/douyin/order_excel_import_review(shopId=${shop.id})}" class="layui-btn layui-btn-primary">导入抖店订单excel</a>
                    </div>
                </div>


            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                
                <th>
                    <input id="allCheck" type="checkbox"/>
                        订单号
                </th>
                <th width="20%">商品</th>
                <th>商品总额</th>
              
                <th>收货信息</th>
                <th>物流信息</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${lists}">
         
                <td >
        
                    <input type="checkbox" class="currCheck" name="orderIds" th:value="${item.orderId}" th:text="${item.orderId}" />
                        <p style="color:#a3a3a3;" th:text="${ item.createTime}"></p>
                </td>
                <td>
                    <div th:each="it:${item.items}"><img
                            th:src="${it.erpGoodsSpecImg}">
                        <p>
                            <span  th:text="${#strings.abbreviate(it.getProductName(),22)}"></span><br/>
                            <span th:text="${it.specDesc}"></span> -- 
                            [[${it.specCode}]]<br/>
                            数量：X[[${it.comboNum.intValue()}]]
                            <span th:if="${it.itemStatus == 4}" style="color: red">已取消</span>
                            <!-- <a href="javascript:;" th:if="${it.itemStatus==0}" th:attr="item-id=${it.id}" class="layui-btn layui-btn-xs layui-btn-primary refund_apply">退货</a> -->
                            <span href="javascript:;" th:if="${it.itemStatus > 0}" style="color: rgb(213, 19, 19);" class="layui-btn-primary">有售后</span>
                            <a href="javascript:;" th:if="${it.itemStatus==0}" style="color: rgb(234, 225, 225);" th:attr="item-id=${it.id}" class="layui-btn-primary refund_apply">退货</a>
                        </p>
                    </div>
                </td>
                <td>¥[[${item.orderTotalAmount}]]</td>

                <td>
                    <span th:if="${#strings.isEmpty(item.getPostReceiver())==false}" th:text="${item.getPostReceiver()}"></span>
                    <span th:if="${#strings.isEmpty(item.getPostTel())==false}" th:text="${item.getPostTel()}"></span><br />
                    <span th:if="${#strings.isEmpty(item.getPostAddr())==false}" th:text="${item.getPostAddr()}"></span>
                    <span th:if="${#strings.isEmpty(item.getPostReceiver())}" th:text="${item.province}"></span>
                    <span th:if="${#strings.isEmpty(item.getPostReceiver())}" th:text="${item.city}"></span>
                    <span th:if="${#strings.isEmpty(item.getPostReceiver())}" th:text="${item.town}"></span>
                    <span th:if="${#strings.isEmpty(item.getPostReceiver())}" th:text="${item.street}"></span>
                    <a href="javascript:;" style="color: #868686" th:attr="data-id=${item.id}" class="hand_address ">
                        <i class="layui-icon layui-icon-location"></i>
                    </a>
                </td>
                <td>
                    <div>
                        <span th:text="${item.getLogisticsCode()}"></span>
                        <span th:text="${item.getLogisticsCompany()}"></span>
                        <p th:text="${item.sendTime}"></p>
                        
                        
                    </div>
                </td>
                <td>
                    <p th:text="${T(com.b2c.entity.enums.third.EnumDouYinOrderStatus).getThirdStatusName(item.getOrderStatus())}"></p>
                    <span th:if="${item.auditStatus == 0 }" style="color: red">待确认</span>
                    <span th:if="${item.auditStatus == 1 }" style="color: red">已确认</span>
                    <a th:if="${item.getAuditStatus()==0 && item.getOrderStatus() !=9}" href="javascript:;" class="layui-btn-xs layui-btn-primary confirm" th:attr="order_id=${item.getOrderId()}">订单确认</a>
                </td>
                <td>
                    <a th:href="@{/douyin/order_detail(id=${item.getOrderId()},shopId=${shop.getId()})}">查看详情</a>
                   
                    <!--<a th:if="${item.getSendStatus()==4 && not #strings.isEmpty(item.getLogisticsCode())}" th:attr="order-id=${item.getOrderId()},code=${item.getLogisticsCode()}" class="order_send" >订单发货</a>-->
                    <a th:if="${item.orderStatus == 2}" class="hand_express layui-btn layui-btn-xs layui-btn-primary" th:attr="data-id=${item.getId()}">手动发货</a>
                    <p th:if="${#strings.isEmpty(item.getBuyerWords())==false}">买家备注:<b th:text="${item.getBuyerWords()}"></b></p>
                    <p th:if="${#strings.isEmpty(item.getSellerWords())==false}">卖家备注:<b th:text="${item.getSellerWords()}"></b></p>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>
    <script type="text/template" id="send-goods">
        <div class="T-box">
            <p><span>快递公司</span>
                <select id="send-company">
                    <option value="">请选择快递公司</option>
                    <option th:each="item:${company}" th:value="${item.getCode()}" th:text="${item.getName()}"></option>
                </select>
            </p>
            <p><span>快递单号</span><input type="text" name="express_code"/></p>
            <p class="T-result"><span>&nbsp;</span><em id="erro"></em></p>
        </div>
    </script>
    <script type="text/template" id="modify_address">
        <div class="T-box">
            <p><span>姓名</span><input type="text" id="userName" name="userName" /></p>
            <p><span>手机号</span><input type="text" id="mobile" name="mobile" /></p>
            <p><span>收货地址</span><input type="text" id="address" name="address"/></p>
        </div>
    </script>
    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;
        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#endTime'
                ,type: 'datetime'
            });
            $(function () {
                var status = '[[${status}]]';
                $("#status").val(status);
                form.render(); //更新全部
                form.render('select'); //刷新select选择框渲染

                $('#allCheck').on('change', function () {
                    var checked = $('#allCheck').prop('checked');
                    $('.currCheck').prop('checked', checked);
                    $('#batch_set_order_type').val('批量关联业务员(' + getNum() + ')')
                });

                $('.currCheck').on('change', function (e) {
                    var allChecked;
                    for (var i = 0; i < $('.currCheck').length; i++) {
                        var checked = $('.currCheck').eq(i).prop('checked');
                        if (!checked) {
                            $('#allCheck').prop('checked', false);
                            $('#batch_set_order_type').val('批量关联业务员(' + getNum() + ')')
                            return;
                        }
                    }
                    $('#allCheck').prop('checked', true);
                    $('#batch_set_order_type').val('批量关联业务员(' + getNum() + ')')
                });

            })

            $(".refund_apply").click(function(){
                var itemId = $(this).attr('item-id');
            
                var obj = $(this).siblings('b').eq(0);

                layer.prompt({
                    formType: 3,
                    title: '请输入退货单ID'
                }, function(value, index, elem){
                    var data = {itemId:itemId, refundId:value};
                    $.ajax({
                        url: "/ajax_douyin/order_refund_apply",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data:JSON.stringify(data),
                        success: function (res) {

                            if(res.code == 0){

                                $(obj).text(value);
                                layer.close(index)
                                layer.msg(res.msg);
                                // location=location;
                            }else
                                layer.alert(res.msg);
                        }
                    });


                });
            });

            //确认订单
            $(".confirm").click(function () {
                var orderId = $(this).attr("order_id");
                //确认订单iframe层
                layer.open({
                    type: 2,
                    title: '订单确认',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['480px', '650px'],
                    content: '/douyin/order_confirm?orderId=' + orderId //iframe的url
                });
            });


            //补充收货地址
            $('.hand_address').click(function (e) {
                e.stopPropagation();
                e.preventDefault();
                var id = $(this).attr('data-id');
                Tips.confirm({
                    title: '补充收货地址',
                    content: $('#modify_address').html(),
                    define: function () {
                        var data = {
                            id: id,
                            name: $("input[name='userName']").val(),
                            mobile: $("input[name='mobile']").val(),
                            address: $("input[name='address']").val()
                        };
                        $.ajax({
                            url: "/ajax_douyin/order_hand_address",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    Tips.alert(res.msg);
                                }
                            }
                        });
                    }
                });
            });

                // 填写物流
                $('.hand_express').click(function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    var id = $(this).attr('data-id');
                    Tips.confirm({
                        title: '手动填写物流信息',
                        content: $('#send-goods').html(),
                        define: function () {
                            var data = {
                                id: id,
                                company: $("#send-company  option:selected").text(),
                                companyCode: $("#send-company  option:selected").val(),
                                code: $("input[name='express_code']").val()
                            };
                            $.ajax({
                                url: "/ajax_douyin/order_hand_send",
                                type: "POST",
                                dataType: 'json',
                                contentType: 'application/json',
                                data: JSON.stringify(data),
                                success: function (res) {
                                    if (res.code == 0) {
                                        Tips.alert('成功', function () {
                                            location.reload(true);
                                        });
                                    } else {
                                        Tips.alert(res.msg);
                                    }
                                }
                            });
                        }
                    });
                });


                $("#upd_order").click(function () {
                    $("#upd_order").hide();
                    $("#upd_order_").show();
                    let startTime = $("#startTime").val();
                    let endTime = $("#endTime").val();
                    let shopId=$(this).attr("shopId");
                    let data = {
                        startTime:startTime,
                        endTime:endTime,
                        shopId:shopId
                    };
                    $.ajax({
                        url: "/ajax_douyin/pull_order",
                        type: "POST",
                        dataType: "JSON",
                        data:JSON.stringify(data),
                        contentType: 'application/json',
                        success: function (res) {
                            if (res.code == 0) {
                                alert(res.msg);
                                location.reload(true);
                            }else {
                                Tips.alert(res.msg);
                            }
                            $("#upd_order").show();
                            $("#upd_order_").hide();
                        }
                    })
                });

            $("#confirm_order").click(function () {
                $("#confirm_order").hide();
                $("#confirm_order_").show();
                let data = {
                    orderId:0
                };
                $.ajax({
                    url: "/ajax_douyin/affirm_order",
                    type: "POST",
                    dataType: "JSON",
                    data:JSON.stringify(data),
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.code == 0) {
                            alert("确认成功");
                            location.reload(true);
                        }else {
                            Tips.alert(res.msg);
                        }
                        $("#confirm_order").show();
                        $("#confirm_order_").hide();
                    }
                })
            });


                //订单发货
                $(".order_send").click(function () {
                    var $this = $(this);
                    var dataObj = {orderId: $this.attr("order-id"),code:$this.attr("code")}
                    $.ajax({
                        url: "/ajax_douyin/send_order",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data: JSON.stringify(dataObj),
                        success: function (res) {
                            if (res.code == 0) {
                                alert("发货成功");
                                location.reload();
                            }else if(res.code==601){
                                alert(res.msg);
                                try {
                                    parent.location.href = res.data;
                                }catch (e) {
                                    location.href = res.data;
                                }
                            }  else {
                                alert(res.msg);
                            }
                        }
                    })
                });

            $("#excel_btn").click(function () {
                //组合条件
                var url = "/douyin/order_list_douyin_export";
                var startTime = $("input[name=startTime]").val();
                var endTime = $("input[name=endTime]").val();
                var status = $("#status").val();
                var shopId= '[[${shopId}]]';
                url+="?shopId="+shopId+"&status="+status;
                if (startTime != '') {
                    url += "&startTime=" + startTime;
                }
                if (startTime != '') {
                    url += "&endTime=" + endTime;
                }
                window.open(url, "_blank");
            })
            $("#excel_upload_btn").click(function () {
                var excel = $("#excel").val();
                if (excel == '') {
                    alert("请选择文件");
                    return false;
                } else if (excel.lastIndexOf(".xls") < 0) {//可判断以.xls和.xlsx结尾的excel
                    alert("只能上传Excel文件");
                } else if (excel.lastIndexOf(".xlsx") < 0) {
                    alert("只能上传Excel文件");
                } else {
                    var url = "/ajax_douyin/zhubo_order_import_excel_settle";
                    // var formData = new FormData($('#execl_form')[0]);

                    var formData = new FormData();
                    formData.append("excel", document.getElementById("excel").files[0]);
                    $(this).hide();
                    $("#excel_upload_btn_").show();
                    $.ajax({
                        url: url,
                        type: "post",
                        data: formData,
                        success: function (result) {
                            $("#excel_upload_btn_").hide();
                            $("#excel_upload_btn").show();
                            // console.log(result);
                            if (result.code == 0) {
                                alert("导入成功");
                            } else {
                                alert("更新失败:" + result.msg);
                            }
                            // alert(JSON.stringify(result));
                            return false;
                        },
                        error: function () {
                            alert("excel上传失败");
                        },
                        cache: false,
                        contentType: false,
                        processData: false
                    });
                }

                return false;
            })
        });

    </script>

</div>
</body>
<html>
